using Digitalmes.Application.Scada.Models;
using Digitalmes.Application.Scada.Services;

namespace Digitalmes.Application.Scada.Commands;

internal sealed class StepTaskCommandHandler(IServiceScopeFactory serviceScopeFactory) : IRequestHandler<StepTaskCommand, ScadaResult>
{
    public async Task<ScadaResult> Handle(StepTaskCommand request, CancellationToken cancellationToken)
    {
        using var scope = serviceScopeFactory.CreateScope();
        var service = scope.ServiceProvider.GetRequiredService<IStepTaskService>();
        StepTaskInput input = new(request.LineCode, request.WsCode, request.SN, request.Index, request.PassResult, request.CycleTime, request.DataList);
        return await service.StepAsync(input, cancellationToken).ConfigureAwait(false);
    }
}
